﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

using Ingenious.Graph;
using MongoDB.Bson;

namespace Ingenious.Core.TestHarness
{
    public class TreeDataTemplateSelector : DataTemplateSelector
    {
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            DataTemplate dataTemplate = null;

            if (item is NodeViewModelList<Guid> || item is NodeViewModelList<ObjectId> )
            {
                dataTemplate = (DataTemplate)App.Current.Resources["NodeListTemplate"];
            }
            else if( item is NodeViewModelItem<Guid> || item is NodeViewModelItem<ObjectId> )
            {
                dataTemplate = (DataTemplate)App.Current.Resources["NodeTemplate"];
            }
            else if (item is INameValuePair)
            {
                INameValuePair nameValuePair = (INameValuePair)item;

                if (nameValuePair.IsLiteral)
                {
                    dataTemplate = (DataTemplate)App.Current.Resources["LiteralNameValuePairTemplate"];
                }
                else
                {
                    dataTemplate = (DataTemplate)App.Current.Resources["ResourceNameValuePairTemplate"];
                }
            }
            else
            {
                // Must be a literal value
                dataTemplate = (DataTemplate)App.Current.Resources["LiteralNodeTemplate"];
            }

            return dataTemplate;
        }
    }
}
